<?php
declare (strict_types = 1);

namespace app\listener;

use app\Request;
use Swoole\Server;
use think\facade\Cache;
use think\facade\Log;
use think\swoole\Websocket;

class SwWsConnect
{
    /**
     * 事件监听处理
     *
     * @return mixed
     */
    public function handle($event,Websocket $ws,Request $request,Server $servera)
    {
        //获取当前用户id
        $fd = $ws->getSender();
        $servera->set([
            'heartbeat_check_interval' => 60, // 60秒检测一次心跳
            'heartbeat_idle_time' => 600, // 连接最大允许空闲10分钟
        ]);

        //获取客户端ip
        $clientIp = $request->server('REMOTE_ADDR');
        
        $ws->to($fd)->emit('userCallback', json_encode([
            'fd'       => $fd,
        ]));


    }
}
